exports.uninstallApplicationTemplate = function(req,res){

    var bodyParams = req.routeInfo.bodyParams;

    //关闭并删除容器服务
    function stopAndRemoveContainer(cb){

        R.Ssh_exec_dockerCommand(`${DockerSH.RemoveAppContainer} ${bodyParams.containerName}`,function(rs){

       
            //判断是否有错误提示
            if(rs.indexOf('Error') != -1){
                return RES.errorResponse(res,"应用容器卸载失败，请重新尝试");
            }else{
                
                cb();
            
            }
            
        })

    }
    
    //删除该容器记录
    function deleteContainerRecord(cb){

        R.SEND_HTTP(
            req,
            res,
            {
                url    : CORE_APIConfig.coreAPI.easydCloudMemberApplicationContainerDelete.Request_Api_Url,  
                method : 'POST',
                data   : {
                    delete_where   : 'cmac_id',
                    cmac_id        : bodyParams.cmat_cmacid,
                    cmac_is_delete : 1
                }
            },
            function (data) {

                cb();

            }
        )
        

    }

    //将云部署方式更新为0（非云部署）
    function updateCloudStatus(cb){

        R.SEND_HTTP(
            req,
            res,
            {
                url    : CORE_APIConfig.coreAPI.easydCloudMemberApplicationTemplateUpdate.Request_Api_Url,  
                method : 'POST',
                data   : {
                    update_where          : 'cmat_id',
                    cmat_id               : bodyParams.cmat_id,
                    cmat_is_cloud_service : 0
                }
            },
            function (data) {

                cb();

            }
        )

        

    }

    F.Serial([
        stopAndRemoveContainer,
        deleteContainerRecord,
        updateCloudStatus
    ],() => {
        RES.successResponse(res);
    })

}